<@cms.vote id=id;vote>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <title>${vote.title!} - ${metadata.alias!}</title>
        <@tools.includePlace path="/common/8ddab9ba-a8aa-4745-86c6-66bf1c2c976c.html"/> <#-- header -->
    </head>
    <body>
        <@tools.includePlace path="/common/c32a4f4a-ff5d-49cf-bb59-5d9784539174.html"/> <#-- 导航 -->

        <div class="banner-l3 position-relative d-flex align-items-center justify-content-center" style="background:#22407c url(${site.sitePath}assets/img/banner-l3-bg-1.png) 50% 50% no-repeat;">
            <div class="container text-center position-relative py-3 py-md-4 text-white">
                <div class="breadcrumbs fs-7 text-white d-inline-flex align-items-center text-opacity-50">
                    <a href="${site.sitePath}">首页</a>
                    &gt; <a href="${site.dynamicPath}member/votelist.html">投票</a>
                </div>
            </div>
        </div>
        <div class="container">
            <article>
                <header class="mt-4">
                    <h1>${vote.title!}</h1>
                    <p>${vote.description}</p>
                    <p class="text-center text-secondary">开始日期:${(vote.startDate)!},截止日期:${(vote.endDate)!}</p>
                </header>
                <div id="content">
                    <#if vote.startDate lt .now && .now lt vote.endDate><#assign available=true/><#else><#assign available=false/></#if>
                    <#if available && user?has_content><@cms.userVote userId=user.id voteId=vote.id><#assign myvote=object/></@cms.userVote></#if>
                    <@cms.voteItemList voteId=vote.id pageSize=500>
                    <ol class="vote">
                        <#list page.list as v>
                        <li>
                            <div class="progress-box">
                                <div class="progress-bar" style="width:${(vote.votes gt 0 && (!available || myvote?has_content))?then(v.votes*100/vote.votes,100)}%;"></div>
                                <div class="progress-text">
                                    <#if available>
                                    <#if myvote?has_content>
                                    <#if myvote.itemId=v.id>
                                    <a href="javascript:unvote('${v.id}');" title="点击取消投票">${v.title} (${v.votes!} 票)</a>
                                    <#else>
                                    ${v.title} (${v.votes!} 票)
                                    </#if>
                                    <#else>
                                    <a href="<#if user?has_content>javascript:vote('${v.id}');<#else>${site.dynamicPath}member/login.html?returnUrl=${site.dynamicPath}member/vote.html?id=${vote.id}</#if>" title="投票后查看">${v.title}</a>
                                    </#if>
                                    <#else>
                                    ${v.title} <span class="float-end">${v.votes*100/vote.votes}%</span>
                                    </#if>
                                </div>
                            </div>
                        </li>
                        </#list>
                    </ol>
                    <p class="text-center text-secondary">${vote.votes!} 人投票</div>
                </@cms.voteItemList>
                <h3>投票记录</h3>
				<@import path="/ftl/tools.ftl" namespace="t"/><#-- 工具 -->
				<@cms.userVoteList voteId=vote.id pageIndex=pageIndex pageSize=10>
				<div class="article-list">
					<#list page.list as a>
						<@t.merge 'itemIds' a.itemId!/>
						<@t.merge 'userIds' a.id.userId!/>
					</#list>
					<@sys.user ids=t.userIds!><#assign userMap=map!/></@sys.user>
					<@cms.voteItem ids=t.itemIds! ><#assign voteItemMap=map!/></@cms.voteItem>
					<#list page.list as a>
					<div class="card py-2 mb-2 comment">
						<div class="d-flex align-items-center">
							<figure class="rounded-circle">
								<img alt="${userMap[a.id.userId?string].nickname}" src="${userMap[a.id.userId?string].cover!(site.sitePath+'assets/img/logo-graphic.png')}">
							</figure>
							<div>
								<a href="${site.dynamicPath}member/userVoteList.html?id=${a.id.userId}" class="fw-bold me-2">${userMap[a.id.userId?string].nickname}</a><span></span>
								<div class="text-secondary text-opacity-50 fs-8"> ${a.createDate?date} </div>
							</div>
						</div>
						<p class="mt-2">
							投给了:《${voteItemMap[a.itemId?string].title}》
						</p>
					</div>
					<#else>
					<div class="card">没有数据</div>
					</#list>
				</div>
				<#assign url=site.dynamicPath+'vote.html?id='+vote.id/>
				<ul class="pagination mt-5 overflow-auto pb-3">
					<li class="page-item">
						<a class="page-link" href="${getPage(url,page.prePage,'pageIndex')}" aria-label="Previous">
							<span aria-hidden="true">«</span>
						</a>
					</li>
					<#assign start=1/>
					<#if (page.pageIndex-5) gt start>
					<#assign start=page.pageIndex-4/>
					</#if>
					<#assign end=page.totalPage/>
					<#if (page.pageIndex+5) lt end>
					<#assign end=page.pageIndex+4/>
					</#if>
					<#list start..end as a>
					<li class="page-item<#if a=page.pageIndex> active</#if>"><a class="page-link" href="${getPage(url,a,'pageIndex')}">${a}</a></li>
					</#list>
					<li class="page-item">
						<a class="page-link" href="${getPage(url,page.nextPage,'pageIndex')}" aria-label="Next">
							<span aria-hidden="true">»</span>
						</a>
					</li>
				</ul>
				</@cms.userVoteList>
            </article>
        </div>
        <script>
            var itemString="itemType=vote&itemId=${vote.id}";
			var templatePath='${.current_template_name?keep_after('/')}';
		</script>
        <@tools.includePlace path="/footer/7f8bacb5-30ca-4641-b66f-987d447b1a85.html"/> <#-- footer -->
        <script>
            <#if user?has_content>
        function vote(itemId){
            $.getJSON('${site.dynamicPath!}vote/vote?itemId='+itemId+'&_csrf=<@tools.csrfToken/>', function(data){
                alert("投票成功!");
                location.reload();
            });
        }
        function unvote(itemId){
            $.getJSON('${site.dynamicPath!}vote/unvote?itemId='+itemId+'&_csrf=<@tools.csrfToken/>', function(data){
                alert("取消投票成功!");
                location.reload();
            });
        }
            </#if>
        </script>
    </body>
</html>
</@cms.vote>
